package com.css.zfzx.sjcj.modules.drill.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.zfzx.sjcj.modules.drill.service.QhDataTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author tao
 * @date 2020-11-19
 */
@Slf4j
@RestController
@RequestMapping("/qh/qhDataTemplates")
public class QhDataTemplateController {
    @Autowired
    private QhDataTemplateService qhDataTemplateService;

    @GetMapping("/download/{name}")
    public RestResponse exportExcel(@PathVariable String name, HttpServletResponse response) {
        RestResponse restResponse = null;
        JSONObject json = new JSONObject();
        try {
            qhDataTemplateService.download(name, response);
            json.put("message", "下载成功!");
            restResponse = RestResponse.succeed(json);
        } catch (Exception e) {
            String errorMsg = "下载失败!";
            log.error(errorMsg, e);
            restResponse = RestResponse.fail(errorMsg);
        }
        return restResponse;
    }

}